﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace UnitTests
{
	public class ThreadCommunicator
	{
		private List<TextMessage> texts = new List<TextMessage>();

		public void AddMessage(string text, bool isPass, int showNumber)
		{
			lock (this.texts)
			{
				this.texts.Add(new TextMessage(text, isPass, showNumber));
			}
		}

		public TextMessage[] GetMessagesAfter(int lastKnownLength)
		{
			TextMessage[] output;

			lock (this.texts)
			{
				List<TextMessage> newMessages = new List<TextMessage>();
				for (int i = lastKnownLength; i < this.texts.Count; ++i)
				{
					newMessages.Add(this.texts[i]);
				}

				output = newMessages.ToArray();
			}
			return output;
		}

		public int Length
		{
			get
			{
				lock (this.texts)
				{
					return this.texts.Count;
				}
			}
		}
	}

	public class TextMessage
	{
		public TextMessage(string text, bool isPass, int showNumber)
		{
			this.IsPass = isPass;
			this.Text = text;
		}

		public bool IsPass { get; private set; }
		public string Text { get; private set; }
		public int ShowNumber { get; private set; }
	}
}
